<template>
    <div style=" position: relative;"><el-card>
            <template #header>
                <!-- 搜索 -->
                <div>
                    <el-select style="width:160px" v-model="find_data.routeSimpleName" placeholder="请选择行程简称" clearable>
                        <el-option v-for="item in routeSimpleName_list" :key="item.value" :label="item.label"
                            :value="item.value" />
                    </el-select>
                    <el-select style="width:120px;margin-left: 10px;" v-model="find_data.serviceMan" placeholder="请选业务员"
                        clearable>
                        <el-option v-for="item in getServiceMans_list" :key="item.ftUserId" :label="item.realName"
                            :value="item.ftUserId" />
                    </el-select>

                    <el-select style="width:100px;margin-left: 10px;" v-model="find_data.timeType"
                        :placeholder="'时间类型'">
                        <el-option :label="'用车时间'" :value="'0'"></el-option>
                        <el-option :label="'下单时间'" :value="'1'"></el-option>
                        <el-option :label="'续团时间'" :value="'2'"></el-option>
                    </el-select>

                    <el-date-picker :default-time="defaultTime" style="margin-left: 10px;width: 340px;"
                        v-model="timeTypeTime" @change="timeTypeTime_btn" type="datetimerange" start-placeholder="开始时间"
                        end-placeholder="结束时间" format="YYYY-MM-DD HH:mm:ss" value-format="YYYY-MM-DD HH:mm:ss" />

                    <el-select v-model="find_data.orderByCondition" :placeholder="'排序'"
                        style="width: 80px;margin-left: 10px;">
                        <el-option :label="'升序'" :value="'0'"></el-option>
                        <el-option :label="'降序'" :value="'1'"></el-option>
                    </el-select>

                    <el-input style="width: 140px;margin-left: 10px;" placeholder="订单号" v-model="find_data.orderNum">
                    </el-input>

                    <el-input style="width: 220px;margin-left: 10px;" placeholder="行程详情/客户/驾驶员/业务员备注"
                        v-model="find_data.details">
                    </el-input>
                    <el-select v-model="find_data.statusList" multiple collapse-tags :placeholder="'订单状态'"
                        style="width: 180px;margin-left: 10px;">
                        <el-option v-for="it in orderStates" :label="it.name" :key="it.id" :value="it.id">
                        </el-option>
                    </el-select>
                    <div style="margin-top:10px;display: flex;">
                        <el-input style="width: 80px;" placeholder="座位数" maxlength="2"
                            onkeyup="this.value = this.value.replace(/^(0+)|[^\d]+/g, '');"
                            v-model="find_data.carSeats">
                        </el-input>
                        <!-- <el-input style="width: 100px;margin-left: 10px;" placeholder="车牌号" maxlength="8"
                            v-model="find_data.plateNum">
                        </el-input>
                        <el-input style="width: 180px;margin-left: 10px;" placeholder="驾驶员姓名/手机号" maxlength="11"
                            v-model="find_data.driverName">
                        </el-input> -->
                        <!-- <el-select @change="cusCompanySimpleName_change" clearable
                            style="width: 200px;margin-left: 10px;" filterable remote
                            :filter-method="findComboCusList_list_handleFilter" v-model="find_data.useCarCompanyId"
                            placeholder="请选择用车单位">
                            <el-option v-for="(item, index) in findComboCusList_list_yongche" :key="index"
                                :label="item.cusCompanySimpleName" :value="item.id">
                                <span style="float: left">{{ item.cusRole }}</span>
                                <span style="
                            float: right;
                            color: var(--el-text-color-secondary);
                            font-size: 13px;
                          ">{{ item.cusRole + '【' + item.cusPhone + '】' + '【' + item.cusCompanySimpleName +
                        '】' }}</span>
                            </el-option>
                        </el-select>
                        <el-select clearable v-model="find_data.useCarDutyUserId" :placeholder="'联系人'"
                            style="width: 180px;margin-left: 10px;">
                            <el-option v-for="it in dutyService_list" :label="it.name" :key="it.id" :value="it.id">
                            </el-option>
                        </el-select>

                        <el-select @change="carCompanyId_change2" clearable style="width: 200px;margin-left: 10px;"
                            v-model="find_data.carCompanyId" placeholder="请选择供车单位">
                            <el-option v-for="(item, index) in findComboCusList_list" :key="index"
                                :label="item.cusCompanySimpleName" :value="item.id">
                                <span style="float: left">{{ item.cusCompanySimpleName }}</span>
                                <span style="
                        float: right;
                        color: var(--el-text-color-secondary);
                        font-size: 13px;
                      ">{{ item.cusRole }}</span>
                            </el-option>
                        </el-select>
                        <el-select clearable v-model="find_data.carDutyUserId" :placeholder="'供车负责人'"
                            style="width: 180px;margin-left: 10px;">
                            <el-option v-for="it in dutyService_list2" :label="it.name" :key="it.id" :value="it.id">
                            </el-option>
                        </el-select> -->
                        <el-button style="margin-left: 20px;height:30px" @click="search_btn" type="primary"
                            icon="Search">搜索</el-button>
                    </div>

                </div>
                <!-- 功能按钮 -->
                <div style="margin-top:10px;display:flex;">
                    <el-button @click="add_btn" type="primary" icon="SuccessFilled">添加</el-button>
                    <el-button @click="copy_btn" type="primary" icon="WarnTriangleFilled">复制订单</el-button>
                    <el-button @click="up_btn" type="warning" icon="SetUp">修改订单</el-button>
                    <el-button @click="confirmOrderPrice_btn" type="warning" icon="Select">确认车价</el-button>
                    <el-button @click="no_btn" type="danger" icon="WarnTriangleFilled">取消下单</el-button>

                    <el-button @click="del_btn" type="danger" icon="CircleCloseFilled">删除订单</el-button>
                    <el-button @click="setHelpGathUrl_btn" type="primary" icon="FullScreen">代收二维码</el-button>

                    <!-- <el-button @click="mer_btn" type="success" icon="Finished">合并订单</el-button> -->
                    <!-- <el-button @click="nomer_btn" type="warning" icon="Finished">取消合并</el-button> -->
                    <!-- <el-button @click="out_btn" type="warning" icon="Share">导出</el-button> -->

                    <!-- <div style="margin-left:15px"> <el-upload :data="{ checkInFile: '单位客户入住信息' }"
                            :headers="{ 'token': GET_TOKEN(), 'Content-Type': 'multipart/form-data' }" class="upload-excel"
                            :action="importCusCheckInData" :show-file-list="false" :on-success="handleAvatarSuccess"
                            :before-upload="beforeAvatarUpload">
                            <el-button type="warning" icon="Share">导入</el-button>
                        </el-upload></div> -->
                </div>
                <div style="display:flex;height:30px;margin-top:5px;align-items: center;background:pink">
                    <b style="color:red;font-weight:700">订单总价:{{ totalPrice }}元</b>
                    <el-divider direction="vertical"></el-divider>
                    <b style="color:green;font-weight:700">已付款:{{ totalAlGathPrice }}元</b>
                    <el-divider direction="vertical"></el-divider>
                    <b style="color:red;font-weight:700">未付款:{{ totalGathSubPrice }}元</b>

                </div>
            </template>
            <div>
                <el-table border @header-dragend='headerdragend' @selection-change="selection_change_btn" height="58vh"
                    ref="multipleTableRef" :data="list_data" style="width: 100%">
                    <el-table-column type="selection" width="35" />
                    <el-table-column label="编号" width="55" fixed type="index" />

                    <template v-for="item in table_data_list_new" :key="item.field">
                        <el-table-column v-if="item.off" :width="item.width" :prop="item.field" :label="item.label">

                            <template v-if="item.field == 'fukuan'" #default="scope">
                                <div v-if="scope.row.payOrderNum">
                                    <el-button type="warning" size="small"
                                        @click="payment_over_btn(scope.$index, scope.row)">取消付款</el-button>
                                </div>
                                <div v-else>
                                    <el-button
                                        v-if="scope.row.status != 'CANCELED' || scope.row.status != 'REFUSED' || scope.row.status != 'DELETE'"
                                        type="danger" size="small"
                                        @click="payment_btn(scope.$index, scope.row)">待付款</el-button>

                                </div>


                            </template>
                            <template v-if="item.field == 'useCarDutyInfo'" #="{ row, column, $index }">
                                <!-- <span>{{
                        row.useCarDutyInfo ? row.useCarDutyInfo.split('-').length > 2 ? row.useCarDutyInfo.split('-')[1] + '-' + row.useCarDutyInfo.split('-')[2] : row.useCarDutyInfo.split('-')[0] + '-' + row.useCarDutyInfo.split('-')[1]
                            : '' }}</span> -->
                                <span>{{ useCarDutyInfo_data_api(row) }}</span>
                            </template>
                            <template v-if="item.field == 'status'" #="{ row, column, $index }">
                                {{ row.status == 'NOT_GRAB' ? '未抢单' : row.status == 'READY_CAR' ? '未派车' :
                                    row.status
                                        ==
                                        'CAR_READY_CONFIRME' ? '未通知' : row.status == 'DRIVER_READY_RECEIVE' ? '师傅未确认' :
                                        row.status ==
                                            'DRIVER_CONFIRMED'
                                            ? '师傅已确认' : row.status == 'START_TAKE_CUS' ? '出发去接客户' : row.status ==
                                                'ON_ROADING' ?
                                                '已出行' :
                                                row.status == 'FINISHED' ? '已完团' : row.status == 'CANCELED' ? '已取消' : row.status
                                                    ==
                                                    'REFUSED'
                                                    ?
                                                    '已拒绝' : row.status == 'DELETE' ? '已删除' : '其他' }}
                                <span v-if="row.accidentList">
                                    <el-button style="color:#fff;font-weight:700"
                                        @click.native="accidentRecord_btn(row)" type="danger"
                                        size="small">异常</el-button>
                                </span>

                            </template>

                            <template v-if="item.field == 'details'" #="{ row, column, $index }">
                                <span>
                                    <span v-if='row.returnId' style='color:red'>【去程】</span>
                                    <span v-if='row.orderId' style='color:red'>【返程】</span>

                                    {{
                                        row.details }}</span>
                            </template>
                            <template v-if="item.field == 'routeSimpleName'" #="{ row, column, $index }">
                                <span :style="row.routeSimpleName.includes('接') ? 'color:#36954e' : 'color:red;'">{{
                                    row.routeSimpleName }}</span>
                            </template>
                            <template v-if="item.field == 'pricealGathPrice'" #="{ row, column, $index }">
                                <span>{{ row.price - row.alGathPrice }} </span>
                            </template>
                            <template v-if="item.field == 'price'" #="{ row, column, $index }">
                                <span>{{ price_api(row) }}</span>

                                <span style="color:red;" v-if="row.couponMoney > 0">
                                    /优惠卷 {{ row.couponMoney }}
                                </span>
                                <span style="color:#0862bb;" v-if="row.pointMoney > 0">
                                    /巴士币 {{ row.pointMoney }}
                                </span>
                                <span v-if="row.helpGathUrl">
                                    <el-button :disabled="isTrustee == 1" style="color:#fff;font-weight:700"
                                        @click.native="setHelpGathUrl_btn2(row)" type="danger"
                                        size="small">代收</el-button>
                                </span>


                            </template>
                            <template v-if="item.field == 'startDate'" #="{ row, column, $index }">
                                <span>{{ row.startTime.split(' ')[0] }}</span>
                            </template>

                            <template v-if="item.field == 'startTime'" #="{ row, column, $index }">
                                <span>{{ row.startTime.split(' ')[1] }}</span>
                            </template>
                            <template v-if="item.field == 'endDate'" #="{ row, column, $index }">
                                <span>{{ row.endTime.split(' ')[0] }}</span>
                            </template>

                            <template v-if="item.field == 'type'" #="{ row, column, $index }">
                                <span :style="row.type == '1' ? 'color:#36954e' : 'color:red;'">{{ row.type ==
                                    '1' ? '包车' : '拼车' }}</span>
                            </template>

                            <template v-if="item.field == 'endTime'" #="{ row, column, $index }">
                                <span>{{ row.endTime.split(' ')[1] }}</span>
                            </template>
                            <template v-if="item.field == 'cusName'" #="{ row, column, $index }">
                                <span>{{ row.cusInfo }}</span>
                            </template>
                            <template v-if="item.field == 'driverName'" #="{ row, column, $index }">
                                <span>{{ row.driverName ? row.driverName + '-' + row.driverPhone : '' }}</span>
                            </template>
                            <template v-if="item.field == 'shareName'" #="{ row, column, $index }">
                                <span>{{ row.shareName }}-{{ row.shareMobile }}</span>
                            </template>
                            <template v-if="item.field == 'regularCarMoney'" #="{ row, column, $index }">
                                <span>{{ row.regularCarMoney > 0 ? row.regularCarMoney + '(' + row.needSeats + '座)'
                                    : row.regularCarMoney }}</span>
                            </template>
                            <template v-if="item.field == 'tolls'" #="{ row, column, $index }">
                                <span>{{ row.isHighSpeed > 0 ? row.tolls : '0' }}</span>
                            </template>

                            <template v-if="item.field == 'isMerge'" #="{ row, column, $index }">
                                <span>{{ row.isMerge == true ? '合并' : '未合并' }}</span>
                            </template>
                        </el-table-column>
                    </template>
                </el-table>
            </div>

            <div style="margin-top:20px">
                <el-pagination @current-change="current_change_btn" @size-change="size_change_btn"
                    v-model:current-page="find_data.page.pageNum" v-model:page-size="find_data.page.pageSize"
                    :page-sizes="[100, 200, 300, 500, 1000]" :background="true"
                    layout="prev, pager, next, jumper,->,sizes,total," :total="total" />
            </div>
        </el-card>
    </div>

    <!-- 弹窗 -->
    <div>
        <!-- 表格筛选 -->
        <div style="position: absolute;top:100px;z-index: 9999;" :style="icon_off ? 'right:0px;' : 'right:110px;'">
            <el-icon @click="icon_btn" :size="20">
                <Setting />
            </el-icon>
            <div v-show="icon_off"
                style=" position: relative;top:-100px;right:140px;width: 130px;height:430px;background:#fff;overflow: hidden;">
                <div class="cols-set" style="background:#fff;width:90%;height:97%;margin:auto;margin-top:10px;">
                    <div>
                        <el-button-group style="display: flex; ">
                            <el-tooltip effect="dark" placement="bottom">
                                <template #content>注意：拖动下面的项，可以改变表格列的顺序，<br />记得点击保存才会永久生效哦！ </template>
                                <el-button style="width:10px" type="primary" icon="WarningFilled"></el-button>
                            </el-tooltip>
                            <el-button title="重置" type="primary" icon="Refresh" @click="resetTableSet"></el-button>
                            <el-button title="保存" type="primary" icon="Check" @click="saveTableSet"></el-button>
                        </el-button-group>
                        <div ref="sortableContainer" class="col-items" style="height:400px; overflow-y: auto; ">
                            <el-checkbox class="drag_it" @change="checkbox_btn" v-for="item in sortedItems"
                                :key="item.field" v-model="item.off" :label="item.label" border>
                            </el-checkbox>
                        </div>

                    </div>
                </div>
            </div>
        </div>

        <addorder v-if="add_off" @disCarMd="disCarMd" :data="add_off"></addorder>
        <copyorder v-if="copy_off" @copyCarMd="copyCarMd" :data="copy_off" :id="copy_id"></copyorder>
        <uporder v-if="up_off" @upCarMd="upCarMd" :data="up_off" :id="up_id"></uporder>
        <payment v-if="payment_off" @paymentCarMd="paymentCarMd" :data="payment_off" :id="payment_id"
            :payment_data='payment_data'></payment>

        <!-- 订单合并-->
        <el-dialog style="margin-top:5vh" v-model="mer_off" title="合并订单" width="80%" :close-on-click-modal='false'>
            <div>

                <el-table border @selection-change="table_list_selection_change_btn" height="60vh"
                    ref="multipleTableRef" :data="mer_list" style="width: 100%">
                    <el-table-column type="selection" width="35" />
                    <el-table-column label="编号" width="55" fixed type="index" />
                    <el-table-column width="120" property="orderNum" label="订单号" />
                    <el-table-column width="120" property="routeSimpleName" label="行程简称" />
                    <el-table-column width="100" label="订单状态">
                        <template v-if="item.field == 'status'" #="{ row, column, $index }">

                            <span>
                                {{ row.status == 'NOT_GRAB' ? '未抢单' : row.status == 'READY_CAR' ? '未派车' :
                                    row.status
                                        ==
                                        'CAR_READY_CONFIRME' ? '未通知' : row.status == 'DRIVER_READY_RECEIVE' ? '师傅未确认' :
                                        row.status ==
                                            'DRIVER_CONFIRMED'
                                            ? '师傅已确认' : row.status == 'START_TAKE_CUS' ? '出发去接客户' : row.status ==
                                                'ON_ROADING' ?
                                                '已出行' :
                                                row.status == 'FINISHED' ? '已完团' : row.status == 'CANCELED' ? '已取消' : row.status
                                                    ==
                                                    'REFUSED'
                                                    ?
                                                    '已拒绝' : row.status == 'DELETE' ? '已删除' : '其他' }}
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column width="120" property="personNum" label="人数" />
                    <el-table-column width="120" property="flightNum" label="航班号" />
                    <el-table-column width="120" label="出发日期">
                        <template #="{ row, column, $index }">
                            <span>{{ row.startTime.split(' ')[0] }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column width="100" label="出发时间">
                        <template #="{ row, column, $index }">
                            <span>{{ row.startTime.split(' ')[1] }}</span>
                        </template>
                    </el-table-column>

                    <el-table-column width="120" property="waitDate" label="可等待时间" />
                    <el-table-column width="220" property="fromLocation" label="起点" />
                    <el-table-column width="220" property="toLocation" label="终点" />
                    <el-table-column width="160" label="乘车人">
                        <template #="{ row, column, $index }">
                            <span>{{ row.cusName }}-{{ row.cusMobile }}</span>
                        </template>
                    </el-table-column>

                    <template v-if="item.field == 'endDate'" #="{ row, column, $index }">
                        <span>{{ row.endTime.split(' ')[0] }}</span>
                    </template>

                    <template v-if="item.field == 'type'" #="{ row, column, $index }">
                        <span>{{ row.type == '1' ? '包车' : '拼车' }}</span>
                    </template>

                    <template v-if="item.field == 'endTime'" #="{ row, column, $index }">
                        <span>{{ row.endTime.split(' ')[1] }}</span>
                    </template>

                    <el-table-column width="100" label="推广人">
                        <template #="{ row, column, $index }">
                            <span v-if="row.shareName">{{ row.shareName }}-{{ row.shareMobile }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column width="100" property="price" label="订单价格" />
                    <el-table-column width="220" property="remark" label="客户备注" />
                    <el-table-column width="120" property="useCarCompanyId" label="用车单位" />
                    <el-table-column width="120" property="useCarName" label="用车负责人 " />
                    <el-table-column width="170" property="addTime" label="添加时间" />
                    <el-table-column width="120" property="isMerge" label="合并标识" />
                    <el-table-column width="100" label="合并标识">
                        <template #="{ row, column, $index }">
                            <span>{{ row.isMerge == true ? '合并' : '未合并' }}</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-button style="margin-left:67vw;margin-top:20px;" @click="mer_add_ok_btn"
                    type="primary">确认合并</el-button>
            </div>


        </el-dialog>
        <!-- 代收二维码 -->
        <el-dialog style="margin-top:5vh" v-model="QRcode.off" title="上传代收二维码与代收金额" width="30%"
            :close-on-click-modal='false'>
            <div style="display: flex;    justify-content: space-evenly;">
                <div>
                    代收二维码:
                    <el-upload style="margin-top: 10px;" class="avatar-uploader" :action="ImageUrl_upload"
                        :headers="{ token: GET_TOKEN() }" :data="{ ftype: 'BACK_SET_DATA_IMG', files: rawFile_list }"
                        :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload" :show-file-list="false">
                        <img v-if="QRcode.helpGathUrl" :src="ImageUrl + QRcode.helpGathUrl" class="avatar" />
                        <el-icon v-else class="avatar-uploader-icon">
                            <Plus />
                        </el-icon>
                    </el-upload>
                    <el-button @click="remove_btn" style='margin: 10px 0px 0px 70px ;' type="danger">删除</el-button>
                </div>
                <div style="margin-left:10px">
                    代收金额:
                    <el-input type="number" placeholder="请输入金额" v-model="QRcode.helpGathPrice">
                    </el-input>
                </div>
            </div>

            <el-button style="margin-left:23vw" type="primary" @click="addQRcodeBtn()">确 定</el-button>
        </el-dialog>
        <!-- 异常报备 -->
        <el-dialog style="margin-top:5vh" v-model="accidentRecord_off" title="异常报备" width="83%"
            :close-on-click-modal='false'>
            <el-table size="medium" border height="500" :row-style="{ height: '100px' }"
                :header-cell-style="{ height: '35px' }" :data="accidentRecord_list">
                <el-table-column property="accidentName" label="报备名称" height="50" width="180"></el-table-column>
                <el-table-column property="accidentContent" label="报备内容" width="200"></el-table-column>
                <el-table-column property="accidentNote" label="报备备注"></el-table-column>
                <el-table-column property="addTime" label="报备时间" width="180"></el-table-column>
                <el-table-column label="报备图片" width="120">

                    <template #="{ row, column, $index }">


                        <el-image :preview-src-list="['https://cba360.com' + row.accidentUrl]" v-if="row.accidentUrl"
                            style="width: 100px; height: 100px" :src="'https://cba360.com' + row.accidentUrl"
                            fit="cover"></el-image>
                        <p v-else style="text-align: center;">无</p>

                    </template>
                </el-table-column>
                <el-table-column label="调度异常处理">
                    <template #="{ row, column, $index }">

                        <div style="color: red;" v-if="row.serviceDisposeContent == '未处理'">
                            未处理
                        </div>
                        <div v-if="row.serviceDisposeContent != '未处理'">内容:{{ row.serviceDisposeContent }}</div>
                        <div v-if="row.serviceDisposeContent != '未处理'">时间:<span style="color: red;">{{
                            row.serviceDisposeTime }}</span>
                        </div>
                        <!-- <el-button v-else-if="row.travelDisposeContent != '未处理'" type="success"
                 @click.native="travelDisposeContent_btn(row)">
                 已处理
               </el-button> -->


                    </template>

                </el-table-column>
                <el-table-column label="旅行社异常处理">

                    <template #="{ row, column, $index }">

                        <el-button v-if="row.travelDisposeContent == '未处理'" type="danger"
                            @click.native="disposeAccident_btn(row)">
                            未处理
                        </el-button>
                        <div v-if="row.travelDisposeContent != '未处理'">内容:{{ row.travelDisposeContent }}</div>
                        <div v-if="row.travelDisposeContent != '未处理'">时间:<span style="color: red;">{{
                            row.travelDisposeTime }}</span>
                        </div>
                        <el-button v-if="row.travelDisposeContent != '未处理'" type="success"
                            @click.native="disposeAccident_btn(row)">
                            修改
                        </el-button>


                    </template>
                </el-table-column>
            </el-table>

        </el-dialog>
        <el-dialog title="处理异常报备" v-model="disposeAccident_off" width="430px">
            <el-input type="textarea" autosize placeholder="请输入内容" v-model="disposeAccidentContent">
            </el-input>


            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="disposeAccident_off = false">取 消</el-button>
                    <el-button type="primary" @click="disposeAccident_data">确 定</el-button>
                </div>
            </template>

        </el-dialog>
    </div>
</template>

<script setup>
import Sortable from 'sortablejs';
import { GET_TOKEN } from '@/utils/token.js'
import { ref, reactive, onMounted, computed, watch } from 'vue'
import {
    getOrderList, findTravelWayInfo, getStationListPages, add, findStationCombo, getStationType, findAddressByLocation, findMapPointList,
    edit, omsorderdelete, getOrderInfo, mergeQuery, merge, omsorderexport, cancelMerge, findComboCusList, getServiceMans,
    adupPrivateSet, getPrivateSetList, getPrice, cancelPay, useCargetOrderList, cancelOrder, useCarcancelPay, confirmOrderPrice,
    deleteOrder, useCarsetHelpGathUrl, useCardisposeAccident,
} from '@/api/original_order_list.js'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
import AMapLoader from "@amap/amap-jsapi-loader"
import { securityJsCode, key, importCusCheckInData, ImageUrl_upload, ImageUrl, line2treeData } from '@/utils/common.js'
import * as XLSX from 'xlsx';
import CircularJSON from 'circular-json'
// import addorder from './add.vue'
// import uporder from './up.vue'

import payment from './payment.vue'

import uporder from './up/index.vue'
import copyorder from './copy/index.vue'
import addorder from './add/index.vue'
onMounted(async () => {

    getPrivateSetList({
        find: '订单列表',
        page: {
            pageNum: 1,
            pageSize: 20,
        },
    }).then(res => {
        if (res.data.list[0]) {
            table_data_list_new.value = JSON.parse(res.data.list[res.data.list.length - 1].dat)
        } else {

            table_data_list_new.value = table_data_list
        }
    })
    Sortable.create(sortableContainer.value, {
        draggable: '.drag_it',
        ghostClass: 'sortable-ghost',
        onEnd: evt => {
            const targetRow = table_data_list_new.value.splice(evt.oldIndex, 1)[0];
            table_data_list_new.value.splice(evt.newIndex, 0, targetRow);


        }
    })
    getServiceMans({

    }).then(res => {
        if (res.code == 1) {
            getServiceMans_list.value = res.data;

        }
    })
    findComboCusList({
        page: {
            pageNum: 1,
            pageSize: 999,
        },

        cusTypeMark: 'CARTEAM',

    }).then(res => {
        findComboCusList_list.value = res.data
    })
    findComboCusList({
        page: {
            pageNum: 1,
            pageSize: 999,
        },



    }).then(res => {
        findComboCusList_list_yongche.value = res.data
        findComboCusList_list_yongche2.value = res.data
    })
    timeTypeTime.value = [new_day(), to_day()]
    find_data.stime = new_day()
    find_data.etime = to_day()
    await list_api()
})
const useCarDutyInfo_data_api = (e) => {
    let data = ''
    if (e.isCompanyCustomer == 1) {

        if (e.virtuallyUseCarInfo) {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.virtuallyUseCarInfo.split('-')[0] + '(' + e.useCarDutyInfo + ')'
        } else {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.useCarDutyInfo
        }

    } else if (e.isCompanyCustomer == 0 && e.companyNum == '8112010001') {

        if (e.virtuallyUseCarInfo) {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.virtuallyUseCarInfo.split('-')[0] + '(' + e.useCarDutyInfo + ')'
        } else {
            let realName = e.realName ? e.realName : '匿名'
            let mobile = e.mobile ? e.mobile : ''
            data = e.useCarDutyInfo
        }
    } else if (e.isCompanyCustomer == 0 && e.companyNum != '8112010001') {
        data = e.virtuallyUseCarInfo ? e.virtuallyUseCarInfo.split('-')[0] : '匿名'
    }


    return data


}
// #region 异常报备
const getDriverCombo_list = ref([])
const accidentRecord_id = ref('')
const accidentRecord_off = ref(false)
const accidentRecord_list = ref([])
const disposeAccident_off = ref(false)
const disposeAccidentContent = ref('')
const serviceDisposeTime = ref('')
const disposeAccident_list = reactive({
    accidentIndex: '',
    id: '',
    serviceDisposeTime: '',
})
const accidentRecord_btn = (e) => {
    accidentRecord_list.value = e.accidentList
    accidentRecord_id.value = e.id
    accidentRecord_off.value = true

}
const disposeAccident_btn = (e) => {
    console.log(e)
    let date = new Date()
    let y = date.getFullYear()
    let m = date.getMonth()
    let d = date.getDate();
    m = (m > 9) ? m : ("0" + m);
    d = (d < 10) ? ("0" + d) : d;
    let hours = date.getHours();
    let minutes = date.getMinutes();
    minutes = minutes < 10 ? '0' + minutes : minutes;
    let seconds = date.getSeconds();
    seconds = seconds < 10 ? '0' + seconds : seconds;
    let inTime = hours + ':' + minutes + ':' + seconds;
    let time = y + '-' + m + '-' + d + ' ' + inTime
    disposeAccident_off.value = true
    disposeAccident_list.id = accidentRecord_id.value
    disposeAccident_list.accidentIndex = e.accidentIndex,
        disposeAccident_list.serviceDisposeTime = time
    disposeAccidentContent.value = e.travelDisposeContent
    serviceDisposeTime.value = e.serviceDisposeTime
}
const disposeAccident_data = () => {
    let ps = {
        accidentIndex: disposeAccident_list.accidentIndex,
        disposeAccidentContent: disposeAccidentContent.value,
        id: accidentRecord_id.value,
    }
    useCardisposeAccident(ps).then(res => {
        if (res.code == 1) {
            list_api()

            disposeAccident_off.value = false
            accidentRecord_off.value = false
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }

    })
}
//#endregion
// 行程简称
const routeSimpleName_list = reactive([
    {
        value: '送天府',
        label: '送天府',
    },
    {
        value: '接天府',
        label: '接天府',
    },
    {
        value: '拼车送天府',
        label: '拼车送天府',
    },
    {
        value: '拼车接天府',
        label: '拼车接天府',
    },
    {
        value: '送双流',
        label: '送双流',
    },
    {
        value: '接双流',
        label: '接双流',
    },
    {
        value: '送东站',
        label: '送东站',
    },
    {
        value: '接东站',
        label: '接东站',
    },
    {
        value: '送西站',
        label: '送西站',
    },
    {
        value: '接西站',
        label: '接西站',
    },
    {
        value: '送南站',
        label: '送南站',
    },
    {
        value: '接南站',
        label: '接南站',
    }, {
        value: '送集合点大巴',
        label: '送集合点大巴',
    },
    {
        value: '接集合点大巴',
        label: '接集合点大巴',
    },
])
//#region 添加
const add_off = ref(false)
const add_btn = () => {
    add_off.value = true
}
const disCarMd = (e, b) => {
    if (e) {
        if (b) {
            list_api()
            // add_off.value = false
            payment_data.value = {}
            payment_data.value = b
            payment_id.value = ''
            payment_id.value = e
            payment_off.value = true
        } else {
            list_api()
            // add_off.value = false
            payment_data.value = {}
            payment_id.value = ''
            payment_id.value = e
            payment_off.value = true
        }

    } else {
        list_api()
        add_off.value = false
    }

}
//#endregion
//#region 复制
const copy_off = ref(false)
const copy_id = ref('')
const copy_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    // if (table_list.value[0].payOrderNum) {
    //     return ElMessage({
    //         message: '该数据已支付不能修改！',
    //         type: 'warning',
    //     })
    // }
    copy_id.value = table_list.value[0].id
    copy_off.value = true
}
const copyCarMd = (e) => {
    if (e) {

        list_api()
        copy_off.value = false
        payment_id.value = ''
        payment_id.value = e
        payment_off.value = true
    } else {
        list_api()
        copy_off.value = false
    }
}

//#endregion

//#region 修改
const up_off = ref(false)
const up_id = ref('')
const up_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    // if (table_list.value[0].payOrderNum) {
    //     return ElMessage({
    //         message: '该数据已支付不能修改！',
    //         type: 'warning',
    //     })
    // }
    up_id.value = table_list.value[0].id
    up_off.value = true
}
const upCarMd = (e) => {
    if (e) {

        list_api()
        up_off.value = false
        payment_id.value = ''
        payment_id.value = e
        payment_off.value = true
    } else {
        list_api()
        up_off.value = false
    }
}

//#endregion

//#region 付费
const payment_id = ref('')
const payment_data = ref({})
const payment_off = ref(false)
const payment_btn = (a, b) => {
    payment_id.value = b.id
    payment_off.value = true
}

const paymentCarMd = (e, b) => {

    list_api()
    payment_off.value = false
    payment_data.value = {}
    if (e) {
        payment_off.value = false
        payment_data.value = {}
        payment_data.value = b

        payment_id.value = ''
        payment_id.value = e
        console.log(payment_data.value, '22222', e, b)
        setTimeout(() => {
            payment_off.value = true
        }, 1000);
    }


}
//#endregion

//#region 取消付费

const payment_over_btn = (a, b) => {
    ElMessageBox.confirm(
        '是否确认取消付款?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            useCarcancelPay({
                id: b.id,
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
            // return ElMessage({
            //         message: '功能暂未开发！',
            //         type: 'warning',
            //     })
        })
        .catch((e) => {
            // if (e == 'cancel') {
            //     ElMessage({
            //         type: 'warning',
            //         message: '取消删除成功',
            //     })
            // }

        })

}


//#endregion

//#region 代收二维码
const QRcode = ref({
    off: false,
    helpGathUrl: '',
    helpGathPrice: '',
})
const setHelpGathUrl_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    QRcode.value.helpGathUrl = table_list.value[0].helpGathUrl
    QRcode.value.helpGathPrice = table_list.value[0].helpGathPrice
    QRcode.value.off = true
}

const addQRcodeBtn = () => {
    let ps = {
        ids: [table_list.value[0].id],
        helpGathUrl: QRcode.value.helpGathUrl,
        helpGathPrice: QRcode.value.helpGathPrice,
    }

    useCarsetHelpGathUrl(ps).then(res => {
        if (res.code == 1) {
            list_api()
            QRcode.value.off = false
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            QRcode.value.off = false
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}

const rawFile_list = ref([])
const handleAvatarSuccess = (response, uploadFile) => {

    QRcode.value.helpGathUrl = response.data.file.url

}

const beforeAvatarUpload = (rawFile) => {
    rawFile_list.value = []
    if (rawFile.type == 'image/jpeg' || rawFile.type == 'image/png' || rawFile.type == 'image/gif') {
        if (rawFile.size / 1024 / 1024 > 5) {
            ElMessage.error('图片大小不能大于5M!')
            return false
        }
    } else {
        ElMessage.error('请上传图片!')
        return false
    }

    rawFile_list.value.push(rawFile)
    return true

}

const remove_btn = () => {
    QRcode.value.helpGathUrl = ''
}
//#endregion


//#region 取消下单

const no_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认取消订单?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {


            cancelOrder({
                id: table_list.value[0].id
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
        })
        .catch((e) => {


        })



}

const confirmOrderPrice_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认车价?',
        {
            confirmButtonText: '确认车价',
            cancelButtonText: '取消确认',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            confirmOrderPrice({
                ids: [table_list.value[0].id],
                isConfirmPrice: 1,
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })

        })
        .catch((e) => {
            confirmOrderPrice({
                ids: [table_list.value[0].id],
                isConfirmPrice: 0,
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })

        })



}



//#endregion

//#region 表格数据处理
const price_api = (e) => {
    let data = ''
    if (e.grabPrice > 0) {
        data = e.grabPrice
    } else {
        data = e.price
    }
    return data
}
const table_data_list = reactive([
    { label: '付款申请', field: 'fukuan', width: 120, off: true },
    { label: '订单状态', field: 'status', width: 120, off: true },
    { label: '行程详情', field: 'details', width: 400, off: true },
    { label: '人数', field: 'personNum', width: 120, off: true },
    { label: '订单价格', field: 'price', width: 200, off: true },
    { label: '保障用车', field: 'ensureMoney', width: 90, off: true },
    { label: '指定用车', field: 'regularCarMoney', width: 90, off: true },
    { label: '高速费', field: 'tolls', width: 100, off: true },
    { label: '应付余额', field: 'pricealGathPrice', width: 100, off: true },
    { label: '车牌', field: 'plateNum', width: 120, off: true },
    { label: '座位数', field: 'needSeats', width: 120, off: true },
    { label: '驾驶员（电话）', field: 'driverName', width: 200, off: true },
    { label: '乘车人', field: 'cusName', width: 200, off: true },
    { label: '订单号', field: 'orderNum', width: 120, off: true },
    { label: '客户备注', field: 'remark', width: 220, off: true },
    { label: '出发日期', field: 'startDate', width: 120, off: true },
    { label: '出发时间', field: 'startTime', width: 100, off: true },
    { label: '起点', field: 'fromLocation', width: 220, off: true },
    { label: '终点', field: 'toLocation', width: 220, off: true },
    { label: '到达日期', field: 'endDate', width: 120, off: true },
    { label: '到达时间', field: 'endTime', width: 100, off: true },
    { label: '订单类型', field: 'type', width: 220, off: true },
    { label: '用车负责人', field: 'useCarDutyInfo', width: 200, off: true },
    { label: '行程简称', field: 'routeSimpleName', width: 120, off: true },
    { label: '添加时间', field: 'addTime', width: 170, off: true },

    // { label: '航班号', field: 'flightNum', width: 120, off: true }, 
    // { label: '可等待时间', field: 'waitDate', width: 120, off: true },
    // { label: '推广人', field: 'shareName', width: 160, off: true },
    // { label: '用车单位', field: 'useCarCompanyId', width: 120, off: true },
    // { label: '合并标识', field: 'isMerge', width: 100, off: true },
])

const table_data_list_new = ref([])
const icon_off = ref(false)
// 创建排序容器的引用
const sortableContainer = ref('')

const icon_btn = () => {
    icon_off.value = !icon_off.value
    console.log(sortableContainer.value)

}
const resetTableSet = () => {
    table_data_list_new.value = JSON.parse(JSON.stringify(table_data_list))

}
const saveTableSet = () => {

    adupPrivateSet({
        dat: JSON.stringify(table_data_list_new.value),
        tbName: '订单列表',
        tbNum: "original_order_list",
    }).then(res => {
        if (res.code == 1) {
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
    icon_off.value = false
}

const checkbox_btn = (e, c) => {
    for (let i = 0; i < table_data_list_new.value.length; i++) {
        if (table_data_list_new.value[i].label == c.target._value) {
            table_data_list_new.value[i].off == e

        }

    }

}

const sortedItems = computed(() => {
    return [...table_data_list_new.value].sort((a, b) => a.id - b.id);
})
//#endregion

// 合并标识
const isMerge_list = reactive([
    {
        value: 'true',
        label: '合并',
    },
    {
        value: 'false',
        label: '未合并',
    },
])

//#region 订单合并
const mer_off = ref(false)
const mer_list = ref([])
//订单合并表格选择
const table_list_table_list = ref([])
const table_list_selection_change_btn = (e) => {
    table_list_table_list.value = e
    console.log(table_list_table_list.value)
}

const mer_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    //87  table_list.value[0].id
    mergeQuery({ id: table_list.value[0].id }).then(res => {
        if (res.code == 1) {
            mer_list.value = res.data
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })

    mer_off.value = true
}
const mer_add_ok_btn = () => {
    if (table_list_table_list.value.length > 2 || table_list_table_list.value.length < 1) {

        return ElMessage({
            message: '请选择一条或两条数据进行合并！',
            type: 'warning',
        })
    }
    let ps = [table_list.value[0].id]
    for (let i = 0; i < table_list_table_list.value.length; i++) {
        ps.push(table_list_table_list.value[i].id)
    }
    merge({ ids: ps }).then(res => {
        if (res.code == 1) {
            list_api()
            mer_off.value = false
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
//#endregion
//#region 取消合并
const nomer_btn = () => {
    if (table_list.value.length != 1) {

        return ElMessage({
            message: '请选择一条数据取消合并！',
            type: 'warning',
        })
    }
    // 115  table_list.value[0].id
    cancelMerge({ id: table_list.value[0].id }).then(res => {
        if (res.code == 1) {
            list_api()
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
//#endregion
//#region 分页列表

const findComboCusList_list_yongche = ref([])
const findComboCusList_list_yongche2 = ref([])
const dutyService_list = ref([])
const findComboCusList_list_handleFilter = (value) => {
    // 自定义筛选逻辑
    if (value) {
        let results = findComboCusList_list_yongche2.value.filter(item => {
            for (let key in item) {
                if (typeof item[key] === 'string' && item[key].includes(value)) {
                    return true;
                }
            }
            return false;
        })
        if (results.length > 0) {
            findComboCusList_list_yongche.value = results
        } else {
            findComboCusList_list_yongche.value = []
        }
    } else {
        findComboCusList_list_yongche.value = findComboCusList_list_yongche2.value
    }
}
const cusCompanySimpleName_change = (e) => {
    for (let i = 0; i < findComboCusList_list_yongche2.value.length; i++) {
        if (e == findComboCusList_list_yongche2.value[i].id) {
            let data = findComboCusList_list_yongche2.value[i].dutyService.split(',')
            dutyService_list.value = []
            console.log(data)

            for (let j = 0; j < data.length; j++) {
                let obj = {}
                obj.id = data[j].split('-')[0]
                obj.name = data[j].split('-')[1]
                obj.phone = data[j].split('-')[2]
                dutyService_list.value.push(obj)
            }
        }
    }
}
const findComboCusList_list = ref([])
const dutyService_list2 = ref([])
const carCompanyId_change2 = (e) => {
    console.log(e)
    for (let i = 0; i < findComboCusList_list.value.length; i++) {
        if (e == findComboCusList_list.value[i].id) {
            let data = findComboCusList_list.value[i].dutyService.split(',')
            dutyService_list2.value = []
            console.log(data)

            for (let j = 0; j < data.length; j++) {
                let obj = {}
                obj.id = data[j].split('-')[0]
                obj.name = data[j].split('-')[1]
                obj.phone = data[j].split('-')[2]
                dutyService_list2.value.push(obj)
            }
        }
    }
}
const orderStates = ref([
    { id: "READY_CAR", name: "未派车" },
    { id: "CAR_READY_CONFIRME", name: "未通知" },
    { id: "DRIVER_READY_RECEIVE", name: "已通知" },
    { id: "DRIVER_CONFIRMED", name: "师傅已确认" },
    { id: "ON_ROADING", name: "已出行" },
    { id: "FINIESHED", name: "已完成" },
    { id: "CANCELED", name: "已取消" },
    { id: "REFUSED", name: "已拒绝" },
    { id: "START_TAKE_CUS", name: "出发去接客户" },
    { id: "DELETE", name: "已删除" },
    //     { id: "PENDING", name: "已待定" },
    //     { id: "GRAB_SUCCESS", name: "抢单成功" },
    //     { id: "TRANS_SUCCESS", name: "转接成功" },

])
const getServiceMans_list = ref([])
const list_data = ref([])
const new_day = () => {
    let today = new Date();

    let year = today.getFullYear();
    let month = today.getMonth() + 1; // 月份是从 0 到 11，所以需要加上 1
    let day = today.getDate();

    // 如果月份或日期小于 10，则在前面补零
    if (month < 10) {
        month = '0' + month;
    }

    if (day < 10) {
        day = '0' + day;
    }

    let formattedDate = `${year}-${month}-${day} 00:00:00`;
    return formattedDate
}
const to_day = () => {
    let today = new Date();
    let tomorrow = new Date(today);
    tomorrow.setDate(tomorrow.getDate() + 1);

    let year = tomorrow.getFullYear();
    let month = tomorrow.getMonth() + 1; // 月份是从 0 到 11，所以需要加上 1
    let day = tomorrow.getDate();

    // 如果月份或日期小于 10，则在前面补零
    if (month < 10) {
        month = '0' + month;
    }

    if (day < 10) {
        day = '0' + day;
    }

    let formattedDate = `${year}-${month}-${day} 23:59:59`;
    return formattedDate
}
const defaultTime = [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
const timeTypeTime = ref([])
const timeTypeTime_btn = (e) => {
    if (e) {
        timeTypeTime.value = e
        find_data.stime = timeTypeTime.value[0]
        find_data.etime = timeTypeTime.value[1]
        find_data.timeType = '0'
    } else {
        timeTypeTime.value = ''
        find_data.stime = ''
        find_data.etime = ''
        find_data.timeType = ''
    }
}
const find_data = reactive({
    page: {
        pageNum: 1,
        pageSize: 100,
    },
    routeSimpleName: '',
    serviceMan: '',
    timeType: '0',
    stime: '',
    etime: '',
    orderByCondition: '0',
    orderNum: '',
    details: '',
    statusList: [],
    carSeats: '',
    plateNum: '',
    driverName: '',
    useCarCompanyId: '',
    useCarDutyUserId: '',
    carCompanyId: '',
    carDutyUserId: '',
    type: '',
})
const total = ref(0)

// 分页器一夜显示多少数据页面
const size_change_btn = () => {
    find_data.page.pageNum = 1
    list_api()
}

// 分页器跳转页面
const current_change_btn = () => {
    list_api()
}
const totalPrice = ref(0)
const totalAlGathPrice = ref(0)
const totalGathSubPrice = ref(0)
const list_api = () => {
    const loading = ElLoading.service({
        lock: true,
        text: '正在加载，中请稍后...',
        background: 'rgba(0, 0, 0, 0.7)',
    })
    let statusList_off = false
    if (!find_data.statusList.length > 0) {

        statusList_off = true
        find_data.statusList = ['NOT_GRAB', 'READY_CAR', 'CAR_READY_CONFIRME', 'DRIVER_READY_RECEIVE', 'DRIVER_CONFIRMED', 'START_TAKE_CUS', 'ON_ROADING', 'FINISHED']
    }

    useCargetOrderList(find_data).then(res => {
        loading.close()
        if (statusList_off) {
            statusList_off = false
            find_data.statusList = []
        }
        list_data.value = res.data.list.list
        total.value = res.data.list.total
        totalPrice.value = res.data.totalPrice
        totalAlGathPrice.value = res.data.totalAlGathPrice
        totalGathSubPrice.value = res.data.totalGathSubPrice
        console.log(totalGathSubPrice.value, ' totalGathSubPrice.value')
    })
}
//#endregion
//#region 表格选择
const table_list = ref([])
const headerdragend = (newWidth, oldWidth, column) => {
    console.log(newWidth, oldWidth, column)
    for (let i = 0; i < table_data_list_new.value.length; i++) {
        if (column.property == table_data_list_new.value[i].field) {
            table_data_list_new.value[i].width = newWidth
        }
    }
}
const selection_change_btn = (e) => {
    table_list.value = e
    console.log(e)
}
//#endregion

//#region 删除
const del_btn = () => {
    if (table_list.value.length < 1) {
        return ElMessage({
            message: '请选择数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认删除订单?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            let ps = []
            for (let i = 0; i < table_list.value.length; i++) {
                ps.push(table_list.value[i].id)
            }

            deleteOrder({
                ids: ps
            }).then(res => {
                if (res.code == 1) {
                    list_api()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })
        })
        .catch((e) => {
            // if (e == 'cancel') {
            //     ElMessage({
            //         type: 'warning',
            //         message: '取消删除成功',
            //     })
            // }

        })

}
//#endregion

//#region 搜索
const search_btn = () => {
    localStorage.setItem('original_order_list', CircularJSON.stringify(find_data))
    list_api()
}
//#endregion


//#region 订单导出
const out_btn = () => {

    omsorderexport(find_data).then(res => {

        if (res.code == 1) {
            const data = [
                ['订单号', '行程简称', '订单状态', '人数', '航班号', '出发日期', '可等待时间', '起点', '终点', '乘车人', '推广人', '订单价格', '客户备注', '用车单位', '用车负责人', '合并标识', '添加时间'],
            ];
            for (let i = 0; i < res.data.length; i++) {
                let ps = {
                    orderNum: res.data[i].orderNum,
                    routeSimpleName: res.data[i].routeSimpleName,
                    status: res.data[i].status == 'READY_CAR' ? '未派车' : res.data[i].status == 'CAR_READY_CONFIRME' ? '待确认' : res.data[i].status == 'DRIVER_READY_RECEIVE' ? '待接单' : res.data[i].status == 'READY_ROAD' ? '未出行' : res.data[i].status == 'ON_ROADING' ? '未完团' : res.data[i].status == 'FINISHED' ? '完成' : '',
                    personNum: res.data[i].personNum,
                    flightNum: res.data[i].flightNum,
                    flightDate: res.data[i].flightDate,
                    waitDate: res.data[i].waitDate,
                    fromLocation: res.data[i].fromLocation,
                    toLocation: res.data[i].toLocation,
                    personNum: res.data[i].cusName + '-' + res.data[i].cusMobile,
                    shareName: res.data[i].shareName + '-' + res.data[i].shareMobile,
                    price: res.data[i].price,
                    remark: res.data[i].remark,
                    useCarCompanyId: res.data[i].useCarCompanyId,
                    useCarName: res.data[i].useCarName,
                    isMerge: res.data[i].isMerge == true ? '合并' : '未合并',
                    addTime: res.data[i].addTime,

                }
                data.push(Object.values(ps))
            }
            const ws = XLSX.utils.aoa_to_sheet(data);
            const wb = XLSX.utils.book_new();
            XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
            XLSX.writeFile(wb, '单位管理系统-订单列表.xlsx');
            list_api()
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }

    })

}
//#endregion
</script>

<style scoped lang='scss'>
.div_map {
    position: relative;
    left: 0;
    top: 0;
}

.map_input {
    width: 100%;
    position: absolute;
    z-index: 1;
    display: flex;
    justify-content: center;

}

.map_input2 {
    width: 100%;
    position: absolute;
    z-index: 1;
    display: flex;
    justify-content: center;
    top: 34px;

}

.div_bg:hover {


    background-color: darkgray;
}
</style>

<style>
.avatar-uploader .avatar {
    width: 200px;
    height: 200px;
    display: block;
}


.avatar-uploader .el-upload {
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 200px;
    height: 200px;
    text-align: center;
}

.el-table .el-table__cell {
    padding: 0px !important;
}



#tab-aircraft_deliver {
    color: red;
}

#tab-train_deliver {
    color: red;
}

#tab-bus_deliver {
    color: red;
}

.col-items::-webkit-scrollbar {
    width: 5px !important;
}

.col-items>label {
    margin-left: 0px !important;
    margin-top: 5px;
    width: 100%;
}
</style>
